﻿using System;

namespace Graph
{
    public class Vertex:IComparable, IComparable<Vertex>
    {
        public string Name { get; private set; }

        public Vertex(string name)
        {
            if(!string.IsNullOrWhiteSpace(name))            
                Name = name;
            else
                throw new ArgumentException("The vertex should have a name");
        }

        public Vertex(Vertex vertex)
            : this(vertex.Name)
        {            
        }

        public int CompareTo(object obj)
        {
            Vertex vertex = obj as Vertex;
            return CompareTo(vertex);
        }

        public virtual int CompareTo(Vertex vertex)
        {            
            if (this.Name.Length > vertex.Name.Length)
                return 1;
            if (this.Name.Length < vertex.Name.Length)
                return -1;
            else return this.Name.CompareTo(vertex.Name);
        }

        public sealed override bool Equals(object obj)
        {
            Vertex vertex = obj as Vertex;
            return vertex != null && this.Name == vertex.Name;
        }

        public sealed override int GetHashCode()
        {
            return Name.GetHashCode();
        }

        public override string ToString()
        {
            return Name;
        }
    }
}
